import { login } from "../../service/user";

Component({
    properties: {},
    data: {},
    lifetimes: {
        ready() {
            this.setData({
                loginStatus: !!wx.getStorageSync('userInfo')
            })
        }
    },
    pageLifetimes: {
        show() {
            this.setData({
                loginStatus: !!wx.getStorageSync('userInfo')
            })
        }
    },
    methods: {
        onClick() {
            if (this.data.loginStatus) {
                this.triggerEvent('click')
            }
        },
        toLogin(e) {
            if (e.detail.userInfo) {
                login()
                    .then(() => {
                        this.triggerEvent('click')
                    })
                    .catch(() => {
                        wx.navigateTo({
                            url: '/pages/login/phone/phone'
                        })
                    })
            } else {
                wx.showToast({
                    title: '请同意获取用户信息，以便为您注册',
                    icon: 'none'
                })
            }
        },
    }
});
